﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Codeblack.TfsScrumboard.Resources;
using Microsoft.TeamFoundation.WorkItemTracking.Client;
using Codeblack.TfsScrumboard.Interfaces;

namespace Codeblack.TfsScrumboard.Entities
{
    public abstract class Backlog
    {
        protected Backlog()
        {
        }

        public Project Project { get; protected set; }

        public string Name { get; protected set; }
        public string IterationPath { get; protected set; }
        public DateTime? StartDate { get; protected set; }
        public DateTime? FinishDate { get; protected set; }
    }

    public class ProductBacklog : Backlog
    {
        public ProductBacklog(Project project)
        {
            this.Project = project;

            this.IterationPath = project.Name;
            this.Name = ScrumboardResources.ProductBacklogName;
        }
    }

    public class SprintBacklog : Backlog
    {
        public SprintBacklog(Project project, WorkItem sprint, IScrumboardSettings scrumboardSettings)
        {
            this.Project = project;

            this.IterationPath = sprint.Fields[scrumboardSettings.Sprints.IterationPathFieldName].Value.ToString();
            this.Name = System.IO.Path.GetFileName(this.IterationPath);
            this.StartDate = sprint.Fields[scrumboardSettings.Sprints.StartDateFieldName].Value as DateTime?;
            this.FinishDate = sprint.Fields[scrumboardSettings.Sprints.FinishDateFieldName].Value as DateTime?;
        }
    }
}
